package com.cms.recursoshumanos.json.object;

import com.cms.recursoshumanos.json.me.JSONException;
import com.cms.recursoshumanos.json.me.JSONObject;

public class JsonObjectServiceProvider {

	public static JsonObjectServiceProvider _instance = null;
	public static JsonObjectServiceProvider getInstance() {
		if(_instance == null)
			_instance = new JsonObjectServiceProvider();
		
		return _instance;
	}
	
	private static final String 
		SERVICEPROVIDER = "Get_Service_Provider",
		SERVICEPROVIDER_DATA = "DATA",
		SERVICEPROVIDER_CONNECTIONCODE = "ConnectionCode",
		SERVICEPROVIDER_CONNECTIONDATA = "ConnectionData";
	
	public String ConnectionCode,
		ConnectionData;
	
	public JsonObjectServiceProvider(){
		ConnectionCode = "";
		ConnectionData = "";
	}
	
	public void fromJSON (String jsonString) {
		ConnectionCode = "";
		ConnectionData = "";
		try{
			JSONObject jsonObject = new JSONObject(jsonString);
		
			if (jsonObject != null) {
				JSONObject service = jsonObject.getJSONObject(SERVICEPROVIDER);
				JSONObject data = service.getJSONObject(SERVICEPROVIDER_DATA);
				
				ConnectionCode = data.getString(SERVICEPROVIDER_CONNECTIONCODE);
				ConnectionData = data.getString(SERVICEPROVIDER_CONNECTIONDATA);
			}
		} catch (JSONException ex) {
			ex.printStackTrace();
		}
	}
	
	public void print() {
		System.out.println("-----------------------------");
		System.out.println("SERVICEPROVIDER: JsonObjectServiceProvider");
		System.out.println("SERVICEPROVIDER_CONNECTIONCODE: 		"+ConnectionCode);
		System.out.println("SERVICEPROVIDER_CONNECTIONDATA: 		"+ConnectionData);
		System.out.println("-----------------------------");
	}
	
	public boolean isUser() {
		if(ConnectionCode == "") 
			return false;
		else return true;
	}
	
}


